// pages/order/order.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    hasUserInfo: false,
    hasLogin: wx.getStorageSync("token") ? true : false,
    showSetting: false,
    menuList: [{
      name: "全部订单"
    }, {
        name: "待付款"
    }, {
        name: "已付款"
    }, {
        name: "已取消"
    }],
    currentTab:''
  },
  detail: function () {
    var that = this
    wx.navigateTo({
      url: '../detail/detail'
    })
  },
  // 获取用户信息
  getUserInfo(res) {
    console.log(res.detail.userInfo)
    let that = this;
    wx.setStorageSync("userName", res.detail.rawData);
    var userName = res.detail.userInfo;
    if (res.detail.userInfo) {
      wx.login({
        success: function (res) {
          let code = res.code;
          console.log(code)
          app.post("/login/check", "post", {}).then(data => {
            if (data.statusCode == "302") {
              wx.navigateTo({
                url: '/pages/login/login?code=' + code + "&nickName=" + userName.nickName + "&avatarUrl=" + userName.avatarUrl
              })
            } else {
              wx.setStorageSync("token", data.token);
              that.setData({ hasLogin: true });
              wx.showToast({
                title: '登录成功'
              })
            }
          }, err => {
            console.log(err)
          })



        }
      })

    } else {

      wx.showToast({ title: '请再次点击授权允许', icon: 'none', duration: 1500 })
      that.setData({ showSetting: true })
    }
  },
  //设置回调
  settingBack: function (res) {
    let that = this;
    if (res.detail.authSetting['scope.userLocation']) {
      that.setData({ showSetting: false });
      that.location();
    }
    if (res.detail.authSetting['scope.userInfo']) {
      that.setData({ showSetting: false });
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },
  
  navItem:function(e){
    var current = e.currentTarget.dataset.current ;
    console.log(current);
    this.setData({
      currentTab: current
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let that = this;
    that.setData({ hasLogin: wx.getStorageSync("token") ? true : false });
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})